home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_349 / med / source / medplayer200src.zoo / load.c < prev    next >
C/C++ Source or Header  |  1990-04-05  |  16KB  |  506 lines

  1. /* MEDPlayer load.c by Teijo Kinnunen 1990 */
  2. #include <workbench/workbench.h>
  3. #include "med.h"
  4. extern struct Kappale far tamakappale;
  5. extern UWORD lohkoja;
  6. extern struct Lohko *blocks[];
  7. extern struct CIA far ciaa;
  8. extern struct Soitin *samples[];
  9. #define M0F_LINEMSK0F    0x1
  10. #define M0F_LINEMSK1F    0x2
  11. #define M0F_FXMSK0F    0x4
  12. #define M0F_FXMSK1F    0x8
  13. #define M0F_LINEMSK00    0x10
  14. #define M0F_LINEMSK10    0x20
  15. #define M0F_FXMSK00    0x40
  16. #define M0F_FXMSK10    0x80
  17. extern void __asm SetTempo(register __d0 UWORD);
  18. typedef LONG Fixed;
  19. typedef LONG IFFP;
  20. typedef IFFP ClientProc();
  21. typedef struct _ClientFrame {
  22.     ClientProc *getList,*getProp,*getForm,*getCat; } ClientFrame;
  23. typedef struct { ULONG oneShotHiSamples, repeatHiSamples, samplesPerHiCycle;
  24.     UWORD samplesPerSec; UBYTE ctOctave, sCompression; Fixed volume; }
  25.     Voice8Header;
  26. typedef struct {
  27.    ClientFrame clientFrame;
  28.    UBYTE foundVHDR;
  29.    UBYTE pad1;
  30.    Voice8Header sampHdr;
  31.    } SVXFrame;
  32. extern SVXFrame smusFrame;
  33. extern BYTE *buf;
  34. extern int szBuf;
  35. extern struct SoundTrackerKappale far ladattu;
  36. static UBYTE *soitinlista = NULL;
  37. static ULONG slistanpituus = NULL;
  38. BOOL LataaKappale();
  39. void LataaSoitinLista(),VapautaSoitinLista();
  40. static BOOL LataaLohkot(),LataaIFFSoitin(),diskerr(),LoadInstrument();
  41. static BOOL NewInstrument();
  42. static BPTR fh = NULL;
  43. static void ConvertTo120(),EtsiHakemisto();
  44. UWORD soittimennum = 1;
  45. UWORD periodit[] = {    856,808,762,720,678,640,604,570,538,508,480,453,
  46.             428,404,381,360,339,320,302,285,269,254,240,226,
  47.             214,202,190,180,170,160,151,143,135,127,120,113,
  48.             214,202,190,180,170,160,151,143,135,127,120,113,
  49.             214,202,190,180,170,160,151,143,135,127,120,113,
  50.             214,202,190,180,170,160,151,143,135,127,120,113 };
  51.  
  52. static BOOL FRead(BPTR fh,char *ptr,long len)
  53. {
  54.     return((BOOL)(Read(fh,ptr,len) != len));
  55. }
  56.  
  57. static UBYTE GetNibble(UBYTE *mem,UWORD *nbnum)
  58. {
  59.     UBYTE *mloc = mem + (*nbnum / 2),res;
  60.     if(*nbnum & 0x1) res = *mloc & 0x0f;
  61.     else res = *mloc >> 4;
  62.     (*nbnum)++;
  63.     return(res);
  64. }
  65.  
  66. static UWORD GetNibbles(UBYTE *mem,UWORD *nbnum,UBYTE nbs)
  67. {
  68.     UWORD res = 0;
  69.     while(nbs--) { res <<= 4; res |= GetNibble(mem,nbnum); }
  70.     return(res);
  71. }
  72.  
  73. static void UnpackBlock(UWORD bnum,UBYTE *from)
  74. {
  75.     UBYTE *to = blocks[bnum]->music,lcnt,trkn = blocks[bnum]->numtracks;
  76.     ULONG linemsk0 = *((ULONG *)from),linemsk1 = *((ULONG *)from + 1);
  77.     ULONG fxmsk0 = *((ULONG *)from + 2),fxmsk1 = *((ULONG *)from + 3);
  78.     ULONG *lmptr = &linemsk0,*fxptr = &fxmsk0;
  79.     UWORD fromn = 0,lmsk;
  80.     UBYTE *fromst = from + 16,bcnt,*tmpto;
  81.     from += 16;
  82.     for(lcnt = 0; lcnt < 64; lcnt++) {
  83.         if(lcnt == 32) { lmptr = &linemsk1; fxptr = &fxmsk1; }
  84.         if(*lmptr & 0x80000000) {
  85.             lmsk = GetNibbles(fromst,&fromn,(UBYTE)(trkn / 4));
  86.             lmsk <<= (16 - trkn);
  87.             tmpto = to;
  88.             for(bcnt = 0; bcnt < trkn; bcnt++) {
  89.                 if(lmsk & 0x8000) {
  90.                     *tmpto = (UBYTE)GetNibbles(fromst,
  91.                         &fromn,2);
  92.                     *(tmpto+1) = (GetNibble(fromst,
  93.                             &fromn) << 4);
  94.                 }
  95.                 lmsk <<= 1; tmpto += 3;
  96.             }
  97.         }
  98.         if(*fxptr & 0x80000000) {
  99.             lmsk = GetNibbles(fromst,&fromn,(UBYTE)(trkn / 4));
  100.             lmsk <<= (16 - trkn);
  101.             tmpto = to;
  102.             for(bcnt = 0; bcnt < trkn; bcnt++) {
  103.                 if(lmsk & 0x8000) {
  104.                     *(tmpto+1) |= GetNibble(fromst,
  105.                             &fromn);
  106.                     *(tmpto+2) = (UBYTE)GetNibbles(
  107.                         fromst,&fromn,2);
  108.                 }
  109.                 lmsk <<= 1; tmpto += 3;
  110.             }
  111.         }
  112.         to += 3 * trkn;
  113.         *lmptr <<= 1; *fxptr <<= 1;
  114.     }
  115. }
  116.  
  117. static BOOL Load120Song(BPTR fh)
  118. {
  119.     ULONG zmsk,*conv = 0;
  120.     UWORD convsz;
  121.     UBYTE scnt,*nameptr,blkcnt;
  122.     Ilmoita("Loading MED2.00-song...");
  123.     if(FRead(fh,(char *)(&zmsk),4)) return(diskerr(fh,0)); /* MED\x03 */
  124.     for(scnt = 0; scnt < 32; scnt++) {
  125.         nameptr = &tamakappale.soitin[scnt][0];
  126.         for(;;) {
  127.             if(FRead(fh,nameptr,1)) return(diskerr(fh,0));
  128.             if(*nameptr++ == '\0') break;
  129.         }
  130.     }
  131.     if(FRead(fh,(char *)(&zmsk),4)) return(diskerr(fh,0));
  132.     for(scnt = 0; scnt < 32; scnt++) {
  133.         if(zmsk & 0x80000000) {
  134.             if(FRead(fh,&tamakappale.soittimenvoimakkuus[scnt],1)) return(diskerr(fh,0));
  135.         } else tamakappale.soittimenvoimakkuus[scnt] = 0;
  136.         zmsk <<= 1;
  137.     }
  138.     if(FRead(fh,(char *)(&zmsk),4)) return(diskerr(fh,0));
  139.     for(scnt = 0; scnt < 32; scnt++) {
  140.         if(zmsk & 0x80000000) {
  141.             if(FRead(fh,(char *)(&tamakappale.stoisto[scnt]),2)) return(diskerr(fh,0));
  142.         } else tamakappale.stoisto[scnt] = 0;
  143.         zmsk <<= 1;
  144.     }
  145.     if(FRead(fh,(char *)(&zmsk),4)) return(diskerr(fh,0));
  146.     for(scnt = 0; scnt < 32; scnt++) {
  147.         if(zmsk & 0x80000000) {
  148.             if(FRead(fh,(char *)(&tamakappale.stoistonpit[scnt]),2)) return(diskerr(fh,0));
  149.         } else tamakappale.stoistonpit[scnt] = 0;
  150.         zmsk <<= 1;
  151.     }
  152.     if(FRead(fh,(char *)(&tamakappale.lohkoja),2)) return(diskerr(fh,0));
  153.     if(FRead(fh,(char *)(&tamakappale.kappaleen_pituus),2)) return(diskerr(fh,0));
  154.     if(FRead(fh,tamakappale.soittojarjestys,tamakappale.kappaleen_pituus)) return(diskerr(fh,0));
  155.     if(FRead(fh,(char *)(&tamakappale.tempo),26)) return(diskerr(fh,0));
  156.     if(FRead(fh,(char *)(&zmsk),4)) return(diskerr(fh,0));
  157.     for(scnt = 0; scnt < 32; scnt++) {
  158.         if(zmsk & 0x80000000) {
  159.             if(FRead(fh,&tamakappale.midikanava[scnt],1)) return(diskerr(fh,0));
  160.         } else tamakappale.midikanava[scnt] = 0;
  161.         zmsk <<= 1;
  162.     }
  163.     if(FRead(fh,(char *)(&zmsk),4)) return(diskerr(fh,0));
  164.     for(scnt = 0; scnt < 32; scnt++) {
  165.         if(zmsk & 0x80000000) {
  166.             if(FRead(fh,&tamakappale.midipreset[scnt],1)) return(diskerr(fh,0));
  167.         } else tamakappale.midipreset[scnt] = 0;
  168.         zmsk <<= 1;
  169.     }
  170.     lohkoja = 0;
  171.     for(blkcnt = 0; blkcnt < tamakappale.lohkoja; blkcnt++) {
  172.         if(FRead(fh,&scnt,1)) return(diskerr(fh,0));
  173.         if(AllocBlock(blkcnt,scnt)) return(diskerr(fh,"No memory."));
  174.         lohkoja++;
  175.         if(FRead(fh,&scnt,1)) return(diskerr(fh,0));
  176.         if(FRead(fh,(char *)(&convsz),2)) return(diskerr(fh,0));
  177.         if(!(conv = AllocMem(convsz+16,MEMF_PUBLIC|MEMF_CLEAR))) return(diskerr(fh,"Memory.."));
  178.         if(scnt & M0F_LINEMSK00) *conv = 0L;
  179.         else if(scnt & M0F_LINEMSK0F) *conv = 0xffffffff;
  180.         else if(FRead(fh,(UBYTE *)conv,4)) return(diskerr(fh,0));
  181.         if(scnt & M0F_LINEMSK10) *(conv+1) = 0L;
  182.         else if(scnt & M0F_LINEMSK1F) *(conv+1) = 0xffffffff;
  183.         else if(FRead(fh,(UBYTE *)(conv + 1),4)) return(diskerr(fh,0));
  184.         if(scnt & M0F_FXMSK00) *(conv+2) = 0L;
  185.         else if(scnt & M0F_FXMSK0F) *(conv+2) = 0xffffffff;
  186.         else if(FRead(fh,(UBYTE *)(conv + 2),4)) return(diskerr(fh,0));
  187.         if(scnt & M0F_FXMSK10) *(conv+3) = 0L;
  188.         else if(scnt & M0F_FXMSK1F) *(conv+3) = 0xffffffff;
  189.         else if(FRead(fh,(UBYTE *)(conv + 3),4)) return(diskerr(fh,0));
  190.         if(FRead(fh,(UBYTE *)(conv + 4),convsz)) return(diskerr(fh,0));
  191.         UnpackBlock((UWORD)blkcnt,(UBYTE *)conv);
  192.         FreeMem(conv,convsz+16); conv = 0;
  193.     }
  194.     return(FALSE);
  195. }
  196.  
  197. static BOOL LoadAttachedInstrs(BPTR fh)
  198. {
  199.     ULONG imsk;
  200.     struct Soitin loaded;
  201.     if(FRead(fh,(char *)(&imsk),4)) return(diskerr(0,0));
  202.     soittimennum = 0;
  203.     while(soittimennum < 31) {
  204.         imsk <<= 1;    /* There's no instrument #0 */
  205.         soittimennum++;
  206.         if(imsk & 0x80000000) {
  207.             if(FRead(fh,(char *)(&loaded),sizeof(struct Soitin)))
  208.                 return(diskerr(0,0));
  209.             if(NewInstrument(loaded.length,soittimennum))
  210.                 return(diskerr(0,"No memory left"));
  211.             samples[soittimennum]->type = loaded.type;
  212.             if(FRead(fh,((char *)samples[soittimennum]) +
  213.                 sizeof(struct Soitin),loaded.length))
  214.                 return(diskerr(0,0));
  215.         }
  216.     }
  217.     return(FALSE);
  218. }
  219.  
  220. static BOOL NewInstrument(ULONG size, UWORD num)
  221. {
  222.     if(samples[num]) {
  223.         FreeMem((void *)samples[num],samples[num]->length +
  224.         sizeof(struct Soitin));
  225.         samples[num] = NULL;
  226.     }
  227.     samples[num] = AllocMem(size + sizeof(struct Soitin),
  228.                 MEMF_PUBLIC|MEMF_CHIP|MEMF_CLEAR);
  229.     if(!samples[num]) return(TRUE);
  230.     samples[num]->length = size;
  231.     return(FALSE);
  232. }
  233.  
  234. static BOOL LoadInstrument(char *name,BOOL src)
  235. {
  236.     ULONG length;
  237.     char latausnimi[100],tunnus[5];
  238.     if(src) EtsiHakemisto(tamakappale.soitin[soittimennum],latausnimi);
  239.     else {
  240.         strcpy(latausnimi,name);
  241.         strcpy(tamakappale.soitin[soittimennum],name);
  242.     }
  243.     if(!(fh = Open(latausnimi,MODE_OLDFILE))) {
  244.         Ilmoita2("Can't find: ",name);
  245.         return(TRUE);
  246.     }
  247.     if(Read(fh,tunnus,4) != 4) return(diskerr(fh,"Too short."));
  248.     tunnus[4] = '\0';
  249.     Ilmoita2("Loading sample: ",name);
  250.     if(!strcmp(tunnus,"FORM")) return(LataaIFFSoitin(fh));
  251.     Seek(fh,0,OFFSET_END);
  252.     length = Seek(fh,0,OFFSET_BEGINNING);
  253.     if(NewInstrument(length,soittimennum)) return(diskerr(0,"No memory."));
  254.     if(Read(fh,(char *)(samples[soittimennum]) + sizeof(struct Soitin),
  255.         length) != length) {
  256.         FreeMem((void *)samples[soittimennum],
  257.                 samples[soittimennum]->length + sizeof(struct Soitin));
  258.         samples[soittimennum] = NULL;
  259.         return(diskerr(0,0));
  260.     }
  261.     Close(fh); fh = NULL;
  262.     return(FALSE);
  263. }
  264.  
  265. BOOL LoadSong(char *nimi)
  266. {
  267.     UWORD scnt;
  268.     char tunnus[5];
  269.     if(!(fh = Open(nimi,MODE_OLDFILE))) return(diskerr(0,0));
  270.     if(Read(fh,tunnus,4) != 4) return(diskerr(fh,"Not a song!"));
  271.     tunnus[4] = '\0';
  272.     Seek(fh,0,OFFSET_BEGINNING);
  273.     if(AllocBlock(0,4)) return(diskerr(fh,"No memory!"));
  274.     lohkoja = 0;
  275.     if(!strcmp(tunnus,"MED\x02")) {
  276.         Ilmoita("Loading MED2.00-song...");
  277.         if(Read(fh,(char *)&tamakappale,sizeof(struct Kappale111)) <
  278.             sizeof(struct Kappale111)) return(diskerr(fh,0));
  279.         if(LataaLohkot(FALSE)) return(diskerr(fh,0));
  280.     } else if(!strcmp(tunnus,"MED\x03")) {
  281.         if(Load120Song(fh)) return(diskerr(fh,0));
  282.     } else {
  283.         if(!strcmp(tunnus,"SONG")) Ilmoita("Loading SoundFX-song...");
  284.         else Ilmoita("Loading SoundTracker-song...");
  285.         if(Read(fh,(char *)&ladattu,sizeof(struct SoundTrackerKappale)) <
  286.             sizeof(struct SoundTrackerKappale)) return(diskerr(fh,"Ei ole kappale"));
  287.         if(LataaLohkot(TRUE)) return(diskerr(fh,0));
  288.         tamakappale.lohkoja = lohkoja;
  289.         tamakappale.tempo = 6;
  290.         tamakappale.kappaleen_pituus = ladattu.st_kappaleen_pit;
  291.         tamakappale.vaihtoja = 5;
  292.         memcpy((char *)(tamakappale.soittojarjestys),
  293.             (char *)(ladattu.st_lohkojarj),100);
  294.         for(scnt = 0; scnt < 15; scnt++) {
  295.             tamakappale.soitin[scnt+1][0] = '\0';
  296.             tamakappale.soittimenvoimakkuus[scnt+1] = ladattu.st_ins[scnt].sti_vol;
  297.             tamakappale.stoisto[scnt+1] = ladattu.st_ins[scnt].sti_repeat;
  298.             tamakappale.stoistonpit[scnt+1] = ladattu.st_ins[scnt].sti_replen * 2;
  299.             strcpy(tamakappale.soitin[scnt+1],ladattu.st_ins[scnt].sti_nimi);
  300.         }
  301.     }
  302.     if(tamakappale.liput & LIPPU_SUODATINPAALLA) ciaa.ciapra &= ~CIAF_LED;
  303.     else ciaa.ciapra |= CIAF_LED;
  304.     soittimennum = 1;
  305.     if(tamakappale.liput & LIPPU_SOITTIMETMUKANA) LoadAttachedInstrs(fh);
  306.     Close(fh); fh = NULL;
  307.     if(!(tamakappale.liput & LIPPU_SOITTIMETMUKANA)) {
  308.         for(scnt = 0; scnt < 31; scnt++) {
  309.             if(tamakappale.soitin[scnt+1][0] && !tamakappale.midikanava[scnt+1])
  310.               LoadInstrument(tamakappale.soitin[scnt+1],TRUE);
  311.             soittimennum++;
  312.         }
  313.     }
  314.     soittimennum = 1;
  315.     Ilmoita("Song is now loaded.");
  316.     return(FALSE);
  317. }
  318.  
  319. static BOOL LataaLohkot(st)
  320. BOOL st; /* SoundTracker ?? */
  321. {
  322.     long jaljella = Seek(fh,0,OFFSET_END),lpt1 = 1024,lpt2 = 1028;
  323.     BOOL error = FALSE;
  324.     ULONG *convblk = AllocMem(1024 + 4,MEMF_PUBLIC|MEMF_CLEAR);
  325.     if(!convblk) return(TRUE);    /* no memory */
  326.     jaljella = Seek(fh,jaljella,OFFSET_BEGINNING) - jaljella;
  327.     for(;;) {
  328.         if(lohkoja >= 100) return(TRUE); /* Apua...ei enää!!!! */
  329.         memset((void *)convblk,0,1028);
  330.         if(st) {
  331.             *convblk = 0L;
  332.             if(lpt1 > jaljella) lpt1 = jaljella;
  333.             if(Read(fh,(char *)(convblk + 1),lpt1)
  334.                 < lpt1) { error = TRUE; break; }
  335.             if((jaljella -= 1024) <= 0) break; /* 0 jäljellä */
  336.         } else {
  337.             if(lpt2 > jaljella) lpt2 = jaljella;
  338.             if(Read(fh,(char *)convblk,lpt2) < lpt2)
  339.                 { error = TRUE; break; }
  340.             if((jaljella -= 1028) <= 0) break;
  341.         }
  342.         ConvertTo120((UBYTE *)convblk,(UBYTE *)blocks[lohkoja]);
  343.         if(AllocBlock(++lohkoja,4)) {
  344.             error = TRUE; /* Out of memory!!*/
  345.             break;
  346.         }
  347.     }
  348.     ConvertTo120((UBYTE *)convblk,(UBYTE *)blocks[lohkoja]);
  349.     lohkoja++;
  350.     FreeMem((void *)convblk,1028);
  351.     return(error);
  352. }
  353.  
  354. static BOOL diskerr(BPTR fh,char *txt)
  355. {
  356.     char virheteksti[45],*virheptr;
  357.     DisplayBeep(0);
  358.     strcpy(virheteksti,"Error: ");
  359.     switch(IoErr()) {
  360.         case 103:    virheptr = "Insufficient free store."; break;
  361.         case 202:    virheptr = "Object in use."; break;
  362.         case 203:    virheptr = "Object already exists."; break;
  363.         case 204:    virheptr = "Directory not found."; break;
  364.         case 205:    virheptr = "Object not found."; break;
  365.         case 210:    virheptr = "Invalid name."; break;
  366.         case 212:    virheptr = "Not of required type."; break;
  367.         case 213:    virheptr = "Disk not validated."; break;
  368.         case 214:    virheptr = "Disk write-protected."; break;
  369.         case 218:    virheptr = "Device not mounted."; break;
  370.         case 221:    virheptr = "Disk full."; break;
  371.         case 222:    virheptr = "File is delete-protected."; break;
  372.         case 223:    virheptr = "File is write-protected."; break;
  373.         case 224:    virheptr = "File is read-protected."; break;
  374.         case 225:    virheptr = "Not a DOS disk."; break;
  375.         case 226:    virheptr = "No disk in drive."; break;
  376.         default:    if(txt) virheptr = txt;
  377.                 else virheptr = "Something is wrong.";
  378.     }
  379.     if(fh) Close(fh);
  380.     strcpy(virheteksti+7,virheptr);
  381.     Ilmoita(virheteksti);
  382.     return(TRUE);
  383. }
  384.  
  385. static BOOL LataaIFFSoitin()
  386. {
  387.     Seek(fh,0,OFFSET_BEGINNING);
  388.     buf = NULL; szBuf = NULL;
  389.     (void)ReadSample(fh);
  390.     Close(fh); fh = NULL;
  391.     if(!buf)    return(diskerr(0,"Failed to load!"));
  392.     if(NewInstrument(szBuf,soittimennum)) Ilmoita("Out of memory!!");
  393.     else {
  394.         memcpy((char *)(samples[soittimennum]) +
  395.             sizeof(struct Soitin),(void *)buf,szBuf);
  396.         switch(smusFrame.sampHdr.ctOctave) {
  397.             case 5:    samples[soittimennum]->type = IFF5OCT;    break;
  398.             case 3:    samples[soittimennum]->type = IFF3OCT;    break;
  399.         }
  400.     }
  401.     FreeMem((void *)buf,szBuf);
  402.     return(FALSE);
  403. }
  404.  
  405. void LataaSoitinLista(char *fname)
  406. {
  407.     UBYTE *scanptr;
  408.     if(fname) {
  409.         Ilmoita2("Searching path file: ",fname);
  410.         fh = Open(fname,MODE_OLDFILE);
  411.     }
  412.     if(!fh) {
  413.         Ilmoita("Searching path file: MED_paths");
  414.         fh = Open("MED_paths",MODE_OLDFILE);
  415.     }
  416.     if(!fh) {
  417.         Ilmoita("Searching path file: S:MED_paths");
  418.         fh = Open("S:MED_paths",MODE_OLDFILE);
  419.     }
  420.     if(!fh) {
  421.         Ilmoita("Couldn't find path file.");
  422.         return; /* ei löytynyt */
  423.     } else Ilmoita("Loading path file...");
  424.     Seek(fh,0,OFFSET_END);
  425.     slistanpituus = Seek(fh,0,OFFSET_BEGINNING);
  426.     if(!(soitinlista = AllocMem(slistanpituus,MEMF_PUBLIC))) {
  427.         Close(fh);
  428.         fh = NULL;
  429.         return;
  430.     }
  431.     Read(fh,soitinlista,slistanpituus);
  432.     Close(fh);
  433.     fh = NULL;
  434.     for(scanptr=soitinlista;scanptr<soitinlista+slistanpituus;scanptr++) {
  435.         if(*scanptr == '\n') *scanptr = '\0';
  436.         if(*scanptr == ':' && *(scanptr+1) == ':') *scanptr = '\0';
  437.         if(*scanptr >= 'a' && *scanptr <= 'z')
  438.             *scanptr = *scanptr - 'a' + 'A'; /* isoiksi */
  439.         /* rivinvaihdot 0:ksi */
  440.     }
  441. }
  442.  
  443. void VapautaSoitinLista()
  444. {
  445.     if(soitinlista) FreeMem((void *)soitinlista,slistanpituus);
  446. }
  447.  
  448. static void EtsiHakemisto(nimi,mihin)
  449. UBYTE *nimi,*mihin;
  450. {
  451.     UBYTE *scanptr = soitinlista,*hakemisto = NULL,isonimi[40],*isoksi = &isonimi[0];
  452.     BOOL loytyi = FALSE;
  453.     if(!scanptr) { /* soitinlistaa ei ole ladattu */
  454.         strcpy(mihin,nimi);
  455.         return;
  456.     }
  457.     if(*nimi == '*' || *nimi == ':') {
  458.         *mihin = '\0'; /* ei hyväksytä! */
  459.         return;
  460.     }
  461.     strcpy(isonimi,nimi);
  462.     while(*isoksi) {
  463.         if(*isoksi >= 'a' && *isoksi <= 'z')
  464.             *isoksi = *isoksi - 'a' + 'A'; /*muutetaan isoksi*/
  465.         isoksi++;
  466.     }
  467.     while(scanptr < soitinlista + slistanpituus) {
  468.         if(*scanptr == '*') hakemisto = scanptr;
  469.         else if(*scanptr == isonimi[0]) { /* tutkitaan 1.merkki */
  470.             if(!strcmp(scanptr,isonimi)) {
  471.                 loytyi = TRUE; /* löytyi !! */
  472.                 break;
  473.             }
  474.         }
  475.         while(*scanptr++ != '\0'); /* etsitään seuraava */
  476.     }
  477.     if(!loytyi) {
  478.         strcpy(mihin,nimi); /* ei löytynyt, kokeillaan sellaisenaan */
  479.         return;
  480.     }
  481.     /* löytyi!! */
  482.     if(hakemisto) strcpy(mihin,hakemisto+1);
  483.         /* kopioidaan hakemiston nimi (alussa '*') */
  484.     strcat(mihin,nimi); /* ja lisätään nimi */
  485. }
  486.  
  487. static void ConvertTo120(from,to)
  488. UBYTE *from,*to;
  489. {
  490.     register UWORD testper,count;
  491.     register UBYTE newnotenum = 0,instrG_V = 0;
  492.     from += 4;    /* skip 4 bytes */
  493.     to += 4;
  494.     for(count = 0; count < (64 * 4); count++) {
  495.         testper = *((UWORD *)from);
  496.         from += 2;
  497.         newnotenum = instrG_V = 0;
  498.         if(testper & 0x9000) { testper &= ~0x9000; instrG_V = 1; }
  499.         if(testper)    while(testper < periodit[newnotenum++]);
  500.         if(instrG_V) newnotenum |= 0x80;
  501.         *to++ = newnotenum;
  502.         *to++ = *from++;
  503.         *to++ = *from++;
  504.     }
  505. }
  506.